<?php
namespace app\controller;

use app\BaseController;
use QL\QueryList;
use app\model\url;
use think\Facade\Db;

class Index extends BaseController
{
    public function index()
    {
        echo "string";
    }

    public function hello($name = 'ThinkPHP6')
    {
    	echo "strss ing";
       
    }
    public function bobo($value='')
    {
    	echo "bobo";
    }


 	public function qqq()
    {
       //采集某页面所有的图片
       $ql = QueryList::get('https://10times.com/san-mateo-county');
       $data = $ql->find('#popup_image')->href;
       //打印结果
       print_r($data);
    }


    public function FunctionName($value='')
    {
    	$str = '\x5B\x22https\x3A\x5C\x2F\x5C\x2Fim.gifbt.com\x5C\x2Fevent\x5C\x2Fd555836e5a93efcf5e5e85b27f293849\x5C\x2F1513489246539\x5C\x2F1513432275.jpg\x22,\x22https\x3A\x5C\x2F\x5C\x2Fim.gifbt.com\x5C\x2Fevent\x5C\x2F952fc96b679340522d399540787f38b\x5C\x2F1513489247664\x5C\x2F1513432277.jpg\x22\x5D';
    	dump(json_decode($str,false));
    }



    public function get($value='')
    {
    	 $curl = curl_init();
		//设置抓取的url
        $url="https://10times.com/ajax?for=scroll&path=/tradeshows&ajax=1&page=2&f_e=507195,511908,297797";                                 //地址要拼接上请求参数

        curl_setopt($curl, CURLOPT_URL, $url);         
        curl_setopt($curl, CURLOPT_HEADER, 1);        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回，而不是直接输出
        $data = curl_exec($curl);                     //执行命令
        curl_close($curl);                            //关闭URL请求
        dump($data);
 
    }


    public function geturl()
    {
        $url_mod = new url();
        $old_url = $url_mod->order('id','desc')->limit(1)->column('url');
        //$url dump(Db::name('url')->column('url'));
        //$url dump(Db::name('url')->column('url'));
         $url = 'https://10times.com'.$old_url[0];
        $ql = QueryList::get($url);
        $data = $ql->find('#popup_image')->href;

        $url_new = new url();
        $url_new->url = $data;
        $res = $url_new->save();
     //   dump($data);
     //    $data = ['url' => $data];
     //    $res = Db::name('url')->save($data);
        dump($res);
    }
}
